<template>
  <div class="classify">
    <div class="top">
      <h1>{{ $route.meta.title }}</h1>
      <el-button type="primary" @click="add">添加品类</el-button>
    </div>
    <p>
      当前商品品类id: <span>{{ $route.params.id }}</span>
    </p>
    <!-- 表格区域 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="品类ID"> </el-table-column>
      <el-table-column prop="name" label="品类名称" width="500">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="update(scope.row)">修改名称</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { addShop, updateClassify } from "@/api/index.js";
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
   
    getData() {
      addShop({ categoryId: this.$route.params.id }).then((res) => {
        this.tableData = res.data.data;
      });
    },

    update(data) {
      let name = prompt("请输入修改后的数据", data.name);
      if (name != null) {
        updateClassify({ categoryId: data.id, categoryName: name }).then(
          (res) => {
            if (res.data.status == 0) {
              alert(res.data.data);
              this.getData();
            }
          }
        );
      }
    },
     add() {
      this.$router.push("/product/index/cate/add");
    },
  },
};
</script>

<style lang="scss" scoped>
.classify {
  .top {
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    align-items: center;
  }
}
h1 {
  font-weight: normal;
}
</style>